<template>
	<view class="loginBox">
		<view class="img"></view>
		<view class="title" @click="back">欢迎登录禹冰之家师傅端</view>
		<view class="content">
			<view class="inputbox">
				<view class="inputboxtext">用户名</view>
				<input v-model="form.username" placeholder-style="color:#ccc;font-size:30rpx" type="text" placeholder="请输入用户名" />
			</view>
			<view class="inputbox">
				<view class="inputboxtext">密码</view>
				<input v-model="form.password" placeholder-style="color:#ccc;font-size:30rpx" type="password" placeholder="请输入密码" />
			</view>
			<view class="login" @click="login">登录</view>
			<view class="agreement">
				<image v-if="isagree==0" @click="choose(1)" style="width:36rpx;height: 36rpx;margin-right: 14rpx;margin-top: 2rpx;" src="../../static/agreed.png" mode="aspectFill"></image>
				<image v-if="isagree==1" @click="choose(0)" style="width:36rpx;height: 36rpx;margin-right: 14rpx;margin-top: 2rpx;" src="../../static/isagreed.png" mode="aspectFill"></image>
				<view class="text">同意并登录<text style="color: #3381FF;" @click="goAgree(1)" >【服务协议】</text>和<text style="color: #3381FF;" @click="goAgree(2)">【隐私保护指引】</text></view>
			</view>
			
			<view class="tips"  @click="toRegister">还没有账号？<span class="register">点击注册</span></view>
		</view>
	</view>
</template>

<script setup>
  import{ref,reactive,getCurrentInstance} from 'vue'
	import {userStore} from '@/store/user.js'//引入空间
	const userStores = userStore()//给空间命名
	const { access_tokenFun } = userStores;//解构函数
	const {proxy} = getCurrentInstance()
	const form = reactive({
		username:'',
		password:'',
		code:'123'
	})
	
	const login = async()=>{
		var data = form
		const result = await proxy.$api.loginAPi(data)
		if(result.code == 200){
			console.log('登录',result);
			access_tokenFun(result.data.access_token)
			uni.setStorageSync('istype','师傅端')
			uni.reLaunch({
			  url:'/pages/home/home?istype='+'师傅端'
			})
		}
	}
	const isagree = ref(false)
	//同意隐私条款
	const choose=(e)=>{
		isagree.value = e
	}
	//查看协议
	const goAgree=(id)=>{
		uni.navigateTo({
			url:'/pages-login/agreement/agreement?id='+id
		})
	}
	const toRegister=()=> {
		uni.navigateTo({
			url: '/pages-shifu/login/register'
		})
	}
			
	
</script>

<style lang="scss">
	.agreement {
		display: flex;
		margin-top: 10rpx;
		align-items: center;
		justify-content: center;
		margin-bottom: 20px;
		width: 600rpx;
	
	
		.checkBox {
			border-radius: 50%;
			border: 2px solid $blue;
			width: 8px;
			height: 8px;
			margin-right: 5px;
		}
	
		.text {
			font-size: 14px;
	
		}
	}
	.loginBox {
		height: 100vh;
		background-color: white;
		position: relative;
		z-index: +1;
		background-color: #ccc;
		.img {
			z-index: -1;
			position: absolute;
			top: 0;
			height: 100vh;
			width:750rpx;
			background: linear-gradient(to bottom, #4E8CFF, #80c4ff, rgba(0, 0, 0, 0));
		}
		.title {
			display: flex;
			align-items: center;
			justify-content: center;
			font-family: '阿里妈妈数黑体';
			color: white;
			font-size: 60rpx;
			padding-top: 300rpx;
			box-sizing: border-box;
		}

		.content {
			background-color: white;
			margin: 0 auto;
			margin-top: 80rpx;
			border-radius: 20rpx;
			width: 690rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-bottom: 60rpx;box-sizing: border-box;
			.inputbox{
				width: 600rpx;height: 90rpx;border-radius: 20rpx;
				border: 1rpx solid #ccc;
				margin-top: 60rpx;display: flex;align-items: center;
				.inputboxtext{
					width: 130rpx;color: #333;font-size: 32rpx;margin-left: 30rpx;
				}
				input{
					padding-left: 30rpx;box-sizing: border-box;
					width: 300rpx;color:#333
				}
			}

			.logo {
				width: 180rpx;
				margin: 40rpx 0;
			}
			.agreement {
				display: flex;
				margin-top: 30rpx;
				align-items: center;
				justify-content: center;
				margin-bottom: 40rpx;
				width: 600rpx;
			}

			.login {
				background-color: #3381FF;
				color: white;
				width: 600rpx;
				text-align: center;
				padding: 20rpx 0;
				border-radius: 10rpx;
				margin: 0 auto;
				margin-top: 60rpx ;
			}
			.tips {
				color: #ccc;
				font-size: 28rpx;
				margin-top: 30rpx;

				.register {
					color: #4E8CFF;
				}
			}
		}

		
	}
</style>